from django.shortcuts import redirect
from rest_framework.response import Response
from rest_framework.views import APIView

from tentimes import settings
from tentimes.utils.qiniuyun import img_upload
# from django.conf import settings
# from fdfs_client.client import Fdfs_client

# ---------------前端富文本编辑器上传图片-------------
class UploadCommomView(APIView):
    def post(self, request):
        data = request.FILES.get('upload')
        image_url = img_upload(data)
        url = "http://127.0.0.1:8080/upload_success.html?image_url=" + image_url + "&CKEditorFuncNum=1"
        return redirect(url)


# ----------------上传图片-------------
class UploadAvatarView(APIView):

    def post(self, request):
        # 七牛云
        data = request.FILES.get('img')
        img_url = img_upload(data)
        # print(img_url)
        return Response({'imgurl': img_url})
